function CHAKANI_SECRET_SetCookie( name, value){
	document.cookie = name + "=" + escape( value )+";path=/;" 
}
function CHAKANI_SECRET_DelCookie( name ){
	document.cookie = name + "=; expires=1;path=/;"
}



function CHAKANI_encode(str){
    var s0, i, s, u;
    s0 = "";                // encoded str
    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                s0 = s0 + s;            
            }
            else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
               }
                else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }

    return s0;
}  	

  	var CHAKANI_Sreq;
  	var mes;
  	var mo = 0, se = 0;
  	function CHAKANI_SECRET_GO(m,s,url){
  		mo = m;
  		se = s;
  		var ans = document.getElementById("CHAKANI_SECRETV_"+m+"_"+s);
  		mes = document.getElementById("CHAKANI_SECRETM_"+m+"_"+s);

  		if ( (gs = m.indexOf("G")) > 0 ) {
  		    m = "guestbook/?page=" + mo.substr(0,gs);
  		}
  		if ( (gs = m.indexOf("N")) > 0 ) {
  		    m = "notice/" + mo.substr(0,gs);
  		}

  		if(!ans.value){
  			mes.innerHTML = "<font color=red>" + lang8 + "</font>";
  		}
  		else{
  			mes.innerHTML = "<font color=blue>" + lang9 + "...</font>";
  			CHAKANI_SECRET_SetCookie("CHAKANI_SECRET_Va", CHAKANI_encode(ans.value)+"_"+mo+"_"+s);
  			CHAKANI_SECRET_SetCookie("CHAKANI_SECRET_No", mo+"_"+s);
  			CHAKANI_Sreq = CHAKANI_S_newXMLHttpRequest();
			CHAKANI_Sreq.onreadystatechange = CHAKANI_S_processReqChange;
			CHAKANI_Sreq.open("POST", url+"/"+m, true);
			CHAKANI_Sreq.setRequestHeader("Content-Type", "text/html");
			CHAKANI_Sreq.send(null);
 		
  		}  		
  	}
  	
  	function CHAKANI_S_processReqChange() {

		if (CHAKANI_Sreq.readyState == 4) {
			
			CHAKANI_SECRET_DelCookie("CHAKANI_SECRET_No");
  			CHAKANI_SECRET_DelCookie("CHAKANI_SECRET_Va");

			if (CHAKANI_Sreq.status == 200) {

				var dataA = CHAKANI_Sreq.responseText;

				var dataT = dataA.split('CHAKANI_SECRET_CODE_');
				if(dataT[1]){
					
					// 데이터에 Script 가 포함되어있을경우 페이지 ReLoad
					var ScriptData = dataA.split('CHAKANI_SECRET_SCRIPT_RELOAD');
					if(ScriptData[1]){
						var ScriptData2 = ScriptData[1].split('|');
				//		location.reload();
						location.href = ScriptData2[1];
					}
					
					// 인증된 비밀글의 갯수를 구한다.
					var dataTE = dataT[1].split('_END');
					var dataTI = dataTE[0].split('|');

					var ss = new Number(dataTI[0])+1;
					var ii = 1;
					
					var dataE;
					var dataS;
					for(ii=1; ii<ss;ii++){
						dataS = dataA.split('CHAKANI_SECRET_START_'+mo+'_'+dataTI[ii]);
						if(dataS[1]){
							dataE = dataS[1].split('CHAKANI_SECRET_END_'+mo+'_'+dataTI[ii]);
							document.getElementById("CHAKANI_SECRET_"+mo+"_"+dataTI[ii]).innerHTML = '<!' + '--' + dataE[0] + '--' + '>';
						}
					}
				}
				else{
					mes.innerHTML = "<font color=red>" + lang10 + "</font>";
				}
				
			}
			else{
				mes.innerHTML = "<font color=red>Error :: " + lang11 + "</font>";
			
			}
		}
	}
				  	
  	function CHAKANI_S_newXMLHttpRequest() {
		var xmlreq = false;
		if (window.XMLHttpRequest) {
			xmlreq = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try {
				xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e1) {
				try {
					xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e2) {
				}
			}
		}
  		return xmlreq;
	}